local shiwang = fk.CreateSkill{
  name = "swis__shiwang",
  tags = {Skill.Lord},
}

local U = require "packages/utility/utility"
local SeabornUtil = require "packages/seaborn/utility/utility"

Fk:loadTranslationTable{
  ["swis__shiwang"] = "世望",
  [":swis__shiwang"] = "主公技，当你参与议事结束后，你可以摸X张牌（X为意见与你相同的其他群势力角色数），然后可以分配至多X张牌。",

  ["#swis__shiwang-distribute"] = "世望：可以分配至多%arg张牌。",

  ["$swis__shiwang"] = "今执牛耳，当为天下之先。",
}

shiwang:addEffect(U.DiscussionFinished, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(shiwang.name) then
      if SeabornUtil.getDiscussionOpinion(player, data) then
        return true
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local op = SeabornUtil.getDiscussionOpinion(player, data)[1]
    local n = #table.filter(room:getOtherPlayers(player, false), function (p)
      local r = SeabornUtil.getDiscussionOpinion(p, data)
      if p.kingdom == "qun" and r then
        return r[1] == op
      end
    end)
    player:drawCards(n, shiwang.name)

    if player:isAlive() then
      room:askToYiji(player, {
        min_num = 1,
        max_num = n,
        skill_name = shiwang.name,
        cancelable = true,
        prompt = "#swis__shiwang-distribute:::"..n,
        cards = player:getCardIds("he"),
        targets = room:getOtherPlayers(player, false),
      })
    end
  end
})

return shiwang